﻿/*
 * ring_buffer.h
 *
 *  Created on: 2019年9月23日
 *      Author: 508
 */

#ifndef SRC_RING_BUFFER_H_
#define SRC_RING_BUFFER_H_
#include <mutex>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>

  //判断x是否是2的次方
#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
//取a和b中最小值
#define Min(a, b) (((a) < (b)) ? (a) : (b))
//#define BUFFER_LEN (1024*4)

typedef struct _ring_buffer
{
	char*      buffer;     //缓冲区
	uint32_t     size;       //大小
	uint32_t     in;         //入口位置
	uint32_t       out;        //出口位置
	//pthread_mutex_t *f_lock;    //互斥锁
}ring_buffer;
//初始化缓冲区

int ring_buffer_init(ring_buffer *p, char*mem, uint32_t size);
uint32_t ring_buffer_len(ring_buffer *ring_buf);
uint32_t ring_buffer_put(ring_buffer *ring_buf, uint8_t *buffer, uint32_t size);
uint32_t ring_buffer_get(ring_buffer *ring_buf, uint8_t *buffer, uint32_t size);


#endif /* SRC_RING_BUFFER_H_ */
